<?php

namespace app\modules\Order\models;

use Yii;

/**
 * This is the model class for table "order_room_customer".
 *
 * @property integer $id
 * @property integer $order_id
 * @property integer $order_room_id
 * @property integer $customer_id
 * @property string $price
 * @property integer $status
 * @property integer $user_id
 * @property string $created_at
 * @property string $updated_at
 */
class OrderRoomCustomer extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'order_room_customer';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['order_id', 'order_room_id'], 'required'],
            [['order_id', 'order_room_id', 'customer_id', 'status', 'user_id'], 'integer'],
            [['price'], 'number'],
            [['created_at', 'updated_at'], 'safe'],
        ];
    }


    // 保存前处理
    public function beforeSave($insert) {//{{{
        if($insert){
            $this->created_at = date("Y-m-d H:i:s");
            $this->user_id    = Yii::$app->user->id;
        }
        return parent::beforeSave($insert);
    }//}}}


    //获取对应的room
    public function getRoom(){
        return $this->hasOne(OrderRoom::className(), ['id' => 'order_room_id']);
    }

    //获取对应的customer
    public function  getOrderCustomer(){
        return $this->hasOne(OrderCustomer::className(),['id'=>'customer_id']);
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app.order', 'ID'),
            'order_id' => Yii::t('app.order', 'Order ID'),
            'order_room_id' => Yii::t('app.order', 'Order Room ID'),
            'customer_id' => Yii::t('app.order', 'Customer ID'),
            'price' => Yii::t('app.order', 'Price'),
            'status' => Yii::t('app.order', 'Status'),
            'user_id' => Yii::t('app.order', 'User ID'),
            'created_at' => Yii::t('app.order', 'Created At'),
            'updated_at' => Yii::t('app.order', 'Updated At'),
        ];
    }
}
